package br.ufc.quixada.sitevendas.servlet;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.ufc.quixada.sitevendas.acao.IAcao;


public class ControladorDeRequisicao extends HttpServlet{
	private static final long serialVersionUID = 1L;

	private void processaRequisicao(HttpServletRequest request, HttpServletResponse response) throws ClassNotFoundException, InstantiationException, IllegalAccessException{
		String acaoRequisitada = "br.ufc.quixada.vendasinfo.acao."+request.getParameter("acao");
		Class<?> classe = Class.forName(acaoRequisitada);
		IAcao acao = (IAcao) classe.newInstance();
		acao.executa(request, response);
	}
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response){
		try {
			processaRequisicao(request, response);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
	}
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response){
		try {
			processaRequisicao(request, response);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
	}

}
